<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'post-form',
        'enableClientValidation'=>true,
        'clientOptions'=>array(
            'validateOnSubmit' => true,
            'validateOnChange' => true,
        ),
        'enableAjaxValidation'=>false,
        'htmlOptions' => array('class' => 'form-horizontal my-form', 'enctype'=>"multipart/form-data")
    )); ?>

<p class="note">Chỉ những trường <span class="required">*</span> là yêu cầu bắt buộc.</p>

<?php echo $form->errorSummary($model); ?>

<fieldset>
    <legend>Nội dung</legend>
    <div class="row">
        <?php echo $form->labelEx($model,'cat_id', array('class' => 'col col-lg-2 control-label')); ?>
        <div class="col col-lg-3">
            <?php echo $form->dropDownList($model,'cat_id', PostCat::model()->getDataGroup(), array(
                    'empty' => 'Chọn chuyên mục', 
                    'class' => 'input-small',
                    'options' => PostCat::model()->getDataForOptionTag()
                )); ?>
            <?php echo $form->error($model,'cat_id');?>
        </div>
    </div>
    <div class="row block-toggle" id="block-type">
        <?php echo $form->labelEx($model,'type', array('class' => 'col col-lg-2 control-label')); ?>
        <div class="col col-lg-3">
            <?php echo $form->dropDownList($model,'type', Post::model()->getTypeData(), array('empty' => '', 'class' => 'input-small')); ?>
            <?php echo $form->error($model,'type');?>
        </div>
    </div>    
    <div class="row block-toggle" id="block-state">
        <?php echo $form->labelEx($model,'state', array('class' => 'col col-lg-2 control-label')); ?>
        <div class="col col-lg-3">
            <?php echo $form->dropDownList($model,'state', Post::model()->getStateData(), array('empty' => '', 'class' => 'input-small')); ?>
            <?php echo $form->error($model,'state');?>
        </div>
    </div>
    
    <div class="row block-toggle" id="block-area-use">
        <?php echo $form->labelEx($model,'area_use', array('class' => 'col col-lg-2 control-label')); ?>
        <div class="col col-lg-3">

            <div class="input-group col col-lg-12">
                <?php echo $form->textField($model,'area_use',array('maxlength'=>255, 'class' => 'input-small numeric format', 'placeholder' => $model->getAttributeLabel('area_use'))); ?>
                <span class="input-group-addon input-small fix-width">m<sup>2</sup></span>
            </div>
            <?php echo $form->error($model,'area_use');?>
        </div>
    </div>
    

    <div class="row block-toggle" id="block-area-floor">
        <?php echo $form->labelEx($model,'area_floor', array('class' => 'col col-lg-2 control-label')); ?>
        <div class="col col-lg-3">
            <div class="input-group">
                <?php echo $form->textField($model,'area_floor',array('maxlength'=>255, 'class' => 'input-small numeric format', 'placeholder' => $model->getAttributeLabel('area_floor'))); ?>
                <span class="input-group-addon input-small fix-width">m<sup>2</sup></span>
            </div>
            <?php echo $form->error($model,'area_floor');?>
        </div>
    </div>


    <div class="row block-toggle" id="block-price">
        <?php echo $form->labelEx($model,'price', array('class' => 'col col-lg-2 control-label')); ?>
        <div class="col col-lg-3">
            <div class="input-group col col-lg-12">
                <?php echo $form->textField($model,'price',array('maxlength'=>255, 'class' => 'input-small numeric format')); ?>
                <span class="input-group-addon input-small fix-width">VNĐ</span>
            </div>
            <?php echo $form->error($model,'price');?>
        </div>
    </div>
    <div class="row">
        <?php echo $form->labelEx($model,'title', array('class' => 'col col-lg-2 control-label')); ?>
        <div class="col col-lg-8">
            <?php echo $form->textField($model,'title', array('maxlength'=>255, 'class' => 'input-small')); ?>
            <?php echo $form->error($model,'title');?>
        </div>
    </div> 
    <div class="row">
        <?php echo $form->labelEx($model,'content', array('class' => 'col col-lg-2 control-label')); ?>
        <div class="col col-lg-10">
            <?php echo $form->textArea($model,'content', array('style' => 'height: 300px')); ?>
            <?php echo $form->error($model,'content');?>
        </div>
    </div> 
</fieldset>


    <div class="row margintop20">
        <div class="col col-lg-12">
<fieldset>
    <legend>Đăng ảnh</legend>
            <?php echo $form->error($model,'image', array('style' => 'margin-left: 0px'));?> 

            <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
            <div class="row fileupload-buttonbar" style="margin-bottom: 20px;">
                <div class="col col-lg-6">
                    <!-- The fileinput-button span is used to style the file input field as button -->
                    <span class="btn btn-success fileinput-button">
                        <i class="icon-plus icon-white"></i> <span>Lấy ảnh từ máy tính</span>
                        <input type="file" name="files[]" multiple>
                    </span> <span>Hoặc kéo & thả ảnh để tải lên</span>
                    <?php /*
                    <button type="submit" class="btn btn-primary start">
                        <i class="icon-upload icon-white"></i>
                        <span>Start upload</span>
                    </button>
                    <button type="reset" class="btn btn-warning cancel">
                        <i class="icon-ban-circle icon-white"></i>
                        <span>Cancel upload</span>
                    </button>
                    <button type="button" class="btn btn-danger delete">
                        <i class="icon-trash icon-white"></i>
                        <span>Delete</span>
                    </button>
                    <input type="checkbox" class="toggle">
                    */?>
                    
                    <!-- The loading indicator is shown during file processing -->
                    <span class="fileupload-loading"></span>
                </div>
                <!-- The global progress information -->
                <div class="col col-lg-6 fileupload-progress fade">
                    <!-- The global progress bar -->
                    <div class="progress progress-striped active" style="margin: 0;" role="progressbar" aria-valuemin="0" aria-valuemax="100">
                        <div class="bar progress-bar" style="width:0%;"></div>
                    </div>
                    <!-- The extended global progress information -->
                    <div class="progress-extended">&nbsp;</div>
                </div>
            </div>
            <!-- The table listing the files available for upload/download -->
            <div id="upload-grid">
                <table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
            </div>
            
</fieldset>
        </div>
    </div>



<div class="row block-toggle margintop20" id="block-address">
    <div class="col col-lg-5">
        <fieldset>
            <legend>Địa chỉ</legend>
            <div class="row">
                <?php echo $form->labelEx($model,'city_id', array('class' => 'col col-lg-5 control-label')); ?>
                <div class="col col-lg-7">
                    <?php echo $form->dropDownList($model,'city_id', City::model()->data, array('class' => 'input-small')); ?>
                    <?php echo $form->error($model,'city_id');?>
                </div>
            </div>
            <div class="row">
                <?php echo $form->labelEx($model,'district_id', array('class' => 'col col-lg-5 control-label')); ?>
                <div class="col col-lg-7">
                    <?php echo $form->dropDownList($model,'district_id', $district_data, array('empty' => '', 'class' => 'input-small')); ?>
                    <?php echo $form->error($model,'district_id');?>
                </div>
            </div>
            <div class="row">
                <?php echo $form->labelEx($model,'address', array('class' => 'col col-lg-5 control-label')); ?>
                <div class="col col-lg-7">
                    <?php echo $form->textField($model,'address',array('maxlength'=>255, 'class' => 'input-small')); ?>
                    <?php echo $form->error($model,'address');?>
                </div>
            </div>
            <div class="row">
                <label class="col col-lg-5 control-label">Địa chỉ đầy đủ</label>                
                <div class="col col-lg-7">
                    <textarea id="address_full" class="input-small" readonly="readonly" rows="2" style="resize: none;"></textarea>
                </div>
            </div> 
            <div class="row">
                <?php echo $form->labelEx($model,'latlng', array('class' => 'col col-lg-5 control-label')); ?>
                <div class="col col-lg-7">
                    <?php echo $form->textField($model,'latlng',array('readonly' => 'readonly','maxlength'=>255, 'class' => 'input-small')); ?>
                    <?php echo $form->error($model,'latlng');?>
                </div>
            </div>
            <div class="row">
                <div class="col col-lg-7 col-offset-5">
                    <?php echo $form->checkBox($model,'show_map',array('class' => 'input-small')); ?>
                    <?php echo $form->labelEx($model,'show_map', array('class' => '')); ?>
                </div>
            </div>
        </fieldset>
    </div>
    <div class="col col-lg-7">
        <fieldset>
            <legend>Bản đồ <span style="font-size: 14px; color: #555;">(kéo thả <u>lá cờ</u> để lấy tọa độ)</span></legend>
            <div id="map" class="well" style="width: 100%; height: 280px; margin: 0;">
                <div style="color: #999999; height: 240px; padding-top: 90px;">
                    <ol>
                        <li>Chọn thành phố, quận huyện để hiển thị bản đồ</li>
                        <li>Chọn tọa độ cho địa chỉ của bạn</li>
                    </ol>
                </div>
            </div>  
        </fieldset>
    </div>

</div>



<hr/>
<?php if(!$model->isNewRecord):?>
<div class="row">
    <?php echo $form->labelEx($model,'status', array('class' => 'col col-lg-2 control-label')); ?>
    <div class="col col-lg-3">
        <?php echo $form->dropDownList($model,'status', Post::model()->getStatusData(), array('class' => 'input-small')); ?>
        <?php echo $form->error($model,'status');?>
    </div>
</div>
<hr/>
<?php endif?>

<div class="row">
    <div class="col col-lg-4 col-offset-2">
        <button class="btn btn-primary" type="submit">
            <?php if($model->isNewRecord):?>
                <i class="icon-plus"></i> Đăng bài
            <?php else:?>
                <i class="icon-edit"></i> Sửa bài
            <?php endif?>
        </button>                               
    </div>
</div>

<?php $this->endWidget(); ?>




<?php /*
<!-- The template to display files available for upload -->     
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-upload fade">
        <td style="width: 0px"></td>
        <td class="preview"><span class="fade"></span></td>
    {% if (file.error) { %}
        <td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td>
        
    {% } else if (o.files.valid && !i) { %}
        <td>   
            <div style="width: 120px" class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar progress-bar progress-bar-success" style="width:0%;"></div></div>
            <div>{%=o.formatFileSize(file.size)%}</div>
        </td>
        <td>
            <button class="btn btn-primary start" style="width: 82px">
                <i class="icon-upload icon-white"></i>
                <span>Upload</span>
            </button>
            {% if (!o.options.autoUpload) { %}
            <br/>
            <br/>
            <button class="btn btn-warning cancel" style="width: 82px">
                <i class="icon-ban-circle icon-white"></i>
                <span>Loại bỏ</span>
            </button>
            {% } %}
        </td>
    {% } %}
    </tr>
{% } %}
</script>


<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl"> 
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-download fade ">
        
    {% if (file.error) { %}
        <td class="error" colspan="3"><span class="label label-danger">Error</span> {%=file.error%}</td>
    {% } else { %}
        <td style="width: 0px">
            <input class="image_cover" {% if (file.is_cover == 1) { %} checked = "checked" {% }%}  type="radio" name="cover" value="{%=file.id%}" title="Chọn làm ảnh đại diện" />
        </td>
        <td class="preview">
            {% if (file.thumbnail_url) { %}
            <a href="{%=file.url%}" title="{%=file.name%}" data-gallery="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
            {% } %}
        </td>
        <td class="name">
            <input type="text" value="{%=file.url%}" class="input-small"/>
        </td>
    {% } %}

        <td>
            <button class="btn btn-danger btn-small delete" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}"{% if (file.delete_with_credentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
            <i class="icon-trash icon-white"></i> <span>Xóa</span>
            </button>
            <input type="checkbox" name="delete" value="1" class="toggle">
        </td>
    </tr>
{% } %}
</script>
*/?>



<!-- The blueimp Gallery widget -->
<div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls" data-filter=":even">
    <div class="slides"></div>
    <h3 class="title"></h3>
    <a class="prev">‹</a>
    <a class="next">›</a>
    <a class="close">×</a>
    <a class="play-pause"></a>
    <ol class="indicator"></ol>
</div>
<!-- The template to display files available for upload -->
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-upload fade">
        <td></td>
        <td>
            <span class="preview"></span>
        </td>
        <td>
            <p class="name">{%=file.name%}</p>
            {% if (file.error) { %}
                <div><span class="label label-important">Error</span> {%=file.error%}</div>
            {% } %}
        </td>
        <td>
            <p class="size">{%=o.formatFileSize(file.size)%}</p>
            {% if (!o.files.error) { %}
                <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar progress-bar" style="width:0%;"></div></div>
            {% } %}
        </td>
        <td>
            {% if (!o.files.error && !i && !o.options.autoUpload) { %}
                <button class="btn btn-primary btn-small start">
                    <i class="icon-upload icon-white"></i>
                    <span>Upload</span>
                </button>
            {% } %}
            {% if (!i) { %}
                <button class="btn btn-warning btn-small cancel">
                    <i class="icon-ban-circle icon-white"></i>
                    <span>Hủy</span>
                </button>
            {% } %}
        </td>
    </tr>
{% } %}
</script>
<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-download fade">
        <td>
            {% if (!file.error) { %}
                <input class="image_cover" {% if (file.is_cover == 1) { %} checked = "checked" {% }%}  type="radio" name="cover" value="{%=file.id%}" title="Chọn làm ảnh đại diện" />
            {% } %}
        </td>
        <td>
            <span class="preview">
                {% if (file.url_thumb) { %}
                    <a href="{%=file.url%}" title="Xem ảnh lớn" download="{%=file.name%}" data-gallery><img src="{%=file.url_thumb%}"></a>
                {% } %}
            </span>
        </td>
        <td>
            <p class="name">
                <a href="" title="Chèn ảnh này vào bài viết" url="{%=file.url%}" class="add_to_content label label-warning"><i class="icon-external-link icon-white"></i> Chèn vào bài viết</a>
            </p>
            {% if (file.error) { %}
                <div><span class="label label-important">Error</span> {%=file.error%}</div>
            {% } %}
        </td>
        <td>
            <span class="size">{%=o.formatFileSize(file.size)%}</span>
        </td>
        <td>
            <button class="btn btn-danger btn-small delete" data-type="{%=file.delete_method%}" data-url="{%=file.delete_url%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
                <i class="icon-trash icon-white"></i>
                <span>Xóa</span>
            </button>
            <?php /*
            <input type="checkbox" name="delete" value="1" class="toggle">
            */?>
        </td>
    </tr>
{% } %}
</script>


<link rel="stylesheet" href="/files/js/blueimp/jquery.gallery/css/blueimp-gallery.min.css">
<link rel="stylesheet" href="/files/js/blueimp/jquery.file.upload/css/jquery.fileupload-ui.css">


<!-- The Templates plugin is included to render the upload/download listings -->
<script src="/files/js/blueimp/javascript.templates/js/tmpl.min.js"></script>
<!-- The Load Image plugin is included for the preview images and image resizing functionality -->
<script src="/files/js/blueimp/javascript.load-image/js/load-image.min.js"></script>
<!-- The Canvas to Blob plugin is included for image resizing functionality -->
<script src="/files/js/blueimp/javascript.canvas-to-blob/js/canvas-to-blob.min.js"></script>

<!-- blueimp Gallery script -->
<script src="/files/js/blueimp/jquery.gallery/js/jquery.blueimp-gallery.min.js"></script>
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
<script src="/files/js/blueimp/jquery.file.upload/js/jquery.iframe-transport.js"></script>
<!-- The basic File Upload plugin -->
<script src="/files/js/blueimp/jquery.file.upload/js/jquery.fileupload.js"></script>
<!-- The File Upload processing plugin -->
<script src="/files/js/blueimp/jquery.file.upload/js/jquery.fileupload-process.js"></script>
<!-- The File Upload image preview & resize plugin -->
<script src="/files/js/blueimp/jquery.file.upload/js/jquery.fileupload-image.js"></script>
<!-- The File Upload validation plugin -->
<script src="/files/js/blueimp/jquery.file.upload/js/jquery.fileupload-validate.js"></script>
<!-- The File Upload user interface plugin -->
<script src="/files/js/blueimp/jquery.file.upload/js/jquery.fileupload-ui.js"></script>
<!-- The XDomainRequest Transport is included for cross-domain file deletion for IE8+ -->
<!--[if gte IE 8]>
<script src="/files/js/jquery.file.upload/js/cors/jquery.xdr-transport.js"></script>
<![endif]-->




<!--[if gte IE 8]><script src="/files/js/jquery.file.upload/js/cors/jquery.xdr-transport.js"></script><![endif]-->
<script>var post_upload_url = '<?php $params = array('action' => $this->action->id); if($model->id) $params['id'] = $model->id; echo $this->createUrl('/hangve/post/upload', $params)?>';</script>



<script type="text/javascript" src="<?php echo $this->googleMapURI?>"></script> 
<script>
    var citiesRefID = <?php echo json_encode(City::model()->getDataRefById())?>;
    var districtsRefID = <?php echo json_encode(District::model()->getDataRefByKey('id'))?>;
    var districtDataGroupByCityId = <?php echo json_encode(District::model()->getDataGroupByCity())?>;
</script>
<script type="text/javascript" src="/files/editor/tinymce402/tinymce.min.js"></script>
<script type="text/javascript" src="<?php echo $this->themeUrl?>/files/js/hangve/post_form.js"></script> 
<script>             
<?php if($this->useMoxie):?>
    tinyMceConfig.plugins[0] += ' moxiemanager'; 
    tinyMceConfig.moxiemanager_rootpath = '/<?php echo $uploadEditorPath?>';
    tinyMceConfig.moxiemanager_extensions = 'jpg,png,gif';
<?php endif?>
tinymce.init(tinyMceConfig);
</script>
<?php if($model->latlng):?><script>google_map('<?php echo $model->latlng?>');</script><?php endif?>
